package com.wft.singleton;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

public class MainTest {
    public static void main(String[] args) throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        List<Thread> threadList = new ArrayList<>();
        for (int i = 0; i < 1000; i++) {
            threadList.add(new Thread(()->{
//                System.out.println(Thread.currentThread() + " ==> " + Test01Hungry.getInstance());
//                System.out.println(Thread.currentThread() + " ==> " + Test02DoubleCheck.getInstance());
//                System.out.println(Thread.currentThread() + " ==> " + Test02Synchronized.getInstance());
//                System.out.println(Thread.currentThread() + " ==> " + Test03StaticInner.getInstance());
//                System.out.println(Thread.currentThread() + " ==> " + Test04Enum.INSTANCE.getInstance());
            }));
        }

        for (Thread thread : threadList) {
            thread.start();
        }

//        new Test01Hungry();

        // can not access a member of class com.wft.singleton.Test01Hungry with modifiers "private"
//        Test01Hungry instance = Test01Hungry.class.newInstance();

        Constructor<Test01Hungry> declaredConstructor = Test01Hungry.class.getDeclaredConstructor();
        declaredConstructor.setAccessible(true);
        Test01Hungry test01Hungry = declaredConstructor.newInstance();
        System.out.println(test01Hungry);
    }
}
